//home组件下的vuex封装
import { reqBaseCategoryList,reqBanners,reqFloors,reqRecommends } from "@/api";

//state
const state = {
  baseCategoryList:[], //三级分类信息state
  banners:[], //首页bannner图
  recommends:[], //首页推荐数据 
  floors:[], //首页楼层数据
}

//mutations
const mutations = {
  //修改CategoryList数据
  receive_base_category_list(state,baseCategoryList){
    state.baseCategoryList = baseCategoryList
  },
  //获取 banners数据
  receive_banners(state,banners){
    state.banners = banners
  },
  //获取 recommends数据
  receive_recommends(state,recommends){
    state.recommends = recommends
  },

  //获取floors数据
   receive_floors(state,floors){
    state.floors = floors
  },
}

//actions
const actions = {
  //action之获取【app中dispatch过来的数据】
  async getBaseCategoryList({commit}){
    const result = await reqBaseCategoryList()
    if(result.code === 200){
      commit('receive_base_category_list',result.data)
    }
  },
  //action之获取【首页轮播图数据】
  async getBanners({commit}){
    const result = await reqBanners()
    if(result.code === 200){
      commit('receive_banners',result.data)
    }
  },
  //action之获取【首页---今日推荐数据】
  async getRecommends({commit}){
    const result = await reqRecommends()
    if(result.code === 200){
      commit('receive_recommends',result.data)
    }
  },

  //action之获取【首页---楼层数据】
  async getFloors({commit}){
    const result = await reqFloors()
    if(result.code === 200){
      commit('receive_floors',result.data)
    }
  }
}

//getters
const getters = {}

export default{
  state,
  mutations,
  actions,
  getters
}